/**
 * 初始化带复选框ztree
 */
jQuery.fn.myztreeCheckbox=function(parameter){
	var param=$.extend({
		zNodes:[
				{ id:1, pId:0, name:"随意勾选 1", open:true},
				{ id:11, pId:1, name:"随意勾选 1-1", open:true},
				{ id:111, pId:11, name:"随意勾选 1-1-1"},
				{ id:112, pId:11, name:"随意勾选 1-1-2"},
				{ id:12, pId:1, name:"随意勾选 1-2", open:true},
				{ id:121, pId:12, name:"随意勾选 1-2-1"},
				{ id:122, pId:12, name:"随意勾选 1-2-2"},
				{ id:2, pId:0, name:"随意勾选 2",  open:true},
				{ id:21, pId:2, name:"随意勾选 2-1"},
				{ id:22, pId:2, name:"随意勾选 2-2", open:true},
				{ id:221, pId:22, name:"随意勾选 2-2-1"},
				{ id:222, pId:22, name:"随意勾选 2-2-2"},
				{ id:23, pId:2, name:"随意勾选 2-3"}
			]
	},parameter);
	
	var id=$(this).attr("id");
	
	var setting = {
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback:{
				onCheck:function(data){
					var zTree = $.fn.zTree.getZTreeObj(id);
					//console.log(zTree);
					//console.log(zTree.getSelectedNodes());
				}
			}
		};

	var code;
		
	function setCheck() {
		var zTree = $.fn.zTree.getZTreeObj(id),
		py = $("#py").attr("checked")? "p":"",
		sy = $("#sy").attr("checked")? "s":"",
		pn = $("#pn").attr("checked")? "p":"",
		sn = $("#sn").attr("checked")? "s":"";
		zTree.setting.check.chkboxType = { "Y" : "p", "N" : "ps" };
	}
	
	$.fn.zTree.init($(this), setting, param.zNodes);
	setCheck();
	$("#py").bind("change", setCheck);
	$("#sy").bind("change", setCheck);
	$("#pn").bind("change", setCheck);
	$("#sn").bind("change", setCheck);
};

//获取用户选中的值
function myztreeGetCheckedIds(htmlId,key,basePath){

	var ids=new Array();
	
	var zTree = $.fn.zTree.getZTreeObj(htmlId);
	
	$.each(zTree.getCheckedNodes(true),function(index,value){
		ids[index]=value.id;
	});
	
	$.ajax({
		url:basePath+'/controller/ztree/setCheckedIds/'+key+'/'+ids,
		dataType:'json',
		async:false,
		success:function(){
			console.log("success");
		},
		error:function(){
			
		}
	});
	
	
	
}